package person;

import java.lang.reflect.Field;

public class ReflectionExample {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        // 创建 Person 对象
        Person person = new Person("Alice", 30);

        Class<Person> pCls = Person.class;

        Field field = pCls.getDeclaredField("name");

        field.setAccessible(true);

        field.set(person, "Bob");

        System.out.println(field.get(person));

        Field field1 = pCls.getDeclaredField("age");

        field1.setAccessible(true);

        field1.set(person, 35);

        System.out.println(field1.get(person));


    }
}
